<?php
/**
 * Created by PhpStorm.
 * User: lwh
 * Date: 2017/7/4
 * Time: 9:43
 */
?>

<!DOCTYPE HTML>
<html lang="en-US">
<head>
    <meta charset="UTF-8">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <title>CrowdFrame绑定</title>
    <link rel="stylesheet" href="css/style.css" />
    <link rel="stylesheet" href="css/bootstrap.min.css" />
    <link href='http://fonts.googleapis.com/css?family=Oleo+Script' rel='stylesheet' type='text/css'>
    <script type="text/javascript" src="js/jquery-1.7.min.js"></script>
    <script type="text/javascript" src="bootstrap.min.js"></script>
    <script type="text/javascript">

        $(document).ready(function(){
            $("#login").click(function(){

                var action = $("#lg-form").attr('action');
                var form_data = {
                    username: $("#username").val(),
                    password: $("#password").val(),
                    userId: getUrlParam("userId"),
                    is_ajax: 1
                };

                $.ajax({
                    type: "POST",
                    url: action,
                    data: form_data,
                    success: function(response)
                    {
						var result = response.trim();
                        //$("#message").html('<p>' + result + '</p>');
                        if(result == "success"){
                            $("#lg-form").slideUp('slow', function(){
                                $("#message").html('<p class="success">绑定成功！</p><p>点击关闭该页面</p>');
                            });
						}
                        else
                            $("#message").html('<p class="error">用户名密码错误！</p>');
                    }
                });
                return false;
            });

            //获取url中的userId参数
            function getUrlParam(name) {
                var reg = new RegExp("(^|&)" + name + "=([^&]*)(&|$)"); //构造一个含有目标参数的正则表达式对象
                var r = window.location.search.substr(1).match(reg);  //匹配目标参数
                if (r != null)
                    return unescape(r[2]);
                return null; //返回参数值
            }
        });
    </script>
</head>
<body>
<div class="container">

    <div class="lg-container row center-block">

        <h1>CrowdFrame</h1>
        <form action="controller/bindCtrl.php" id="lg-form" name="lg-form" method="post">

            <div>
                <label for="username">用户名:</label>
                <input type="text" name="username" id="username" placeholder="用户名"/>
            </div>

            <div>
                <label for="password">密码:</label>
                <input type="password" name="password" id="password" placeholder="密码" />
            </div>

            <div>
                <button type="submit" id="login">绑定</button>
            </div>

        </form>
        <div id="message"></div>

    </div>

</div>

</body>
</html>
